var sname = "";//树形结构的选中值 树形结构ID
//初始加载
$(document).ready(function(){
    queryZyTree();//获取树形结构
    $("#table_list").css("height",($("body").height()-100));
});

//查询值域树
function queryZyTree(){
    $.ajax({
        type:"GET",
        dataType:"json",
        url:"zygl/queryZyTree",
        success:function(jsonData){
            if(jsonData.code == 200){
                initJgTree(jsonData.list);
            }
        }
    });
}


//初始化加载树
function initJgTree(jsonTreeData){
    $.fn.zTree.init($('#table_list'),setting,jsonTreeData);
    fuzzySearch('table_list','#zymc',null,true);
    var treeObj = $.fn.zTree.getZTreeObj("table_list");
    var nodes = treeObj.getNodes();
    if(nodes.length>0){
        if(sname!='' && sname!=null){
            var node = treeObj.getNodeByParam("id",sname);
            treeObj.selectNode(node,true);//将指定ID的节点选中
            treeObj.expandNode(node,true,true,true);
        }else{
            var node=nodes[0];
            if(node.children.length>0){
                node=nodes[0].children;
            }
            sname = node[0].id;
            treeObj.selectNode(node[0]);
            treeObj.expandNode(node[0],true,true,true);
        }
    }
}

var setting = {//树形配置
    view: {
        fontCss: {"font-family":"Microsoft YaHei"},
        selectedMulti: false,
        showIcon:false
    },
    edit: {
        enable: true,
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        onClick: zTreeOnClick,
    }
};

//点击树操作
function zTreeOnClick(event,treeId,treeNode){
   // treeClick(treeNode.id,treeNode.pId);
    console.log(treeNode)
    if(treeNode.level!='0'){
        for(var k=0;k<parent.frames.length;k++){
            if(parent.frames[k].frameElement.src.indexOf("psms-sjygl-add.html")!=-1)
                 parent.frames[k].setSjyyxz(treeNode.name);
        }
    }
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index)
}



